package cn.Mmovie.servlet;

import cn.Mmovie.service.AuditoriumService;
import cn.Mmovie.service.CinemaService;
import cn.Mmovie.service.impl.AuditoriumServiceImpl;
import cn.Mmovie.service.impl.CinemaServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "AdminAuditoriumDeleteServlet", value = "/admin/auditorium_delete")
public class AdminAuditoriumDeleteServlet extends HttpServlet {
    private AuditoriumService auditoriumService=new AuditoriumServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        if (request.getParameter("id")==null||request.getParameter("id")==""){
            request.setAttribute("failMsg","您未选择需要删除的放映厅，请重试！");
            request.getRequestDispatcher("/admin/auditorium_list?cinemaId="+request.getParameter("cinemaId")).forward(request,response);
        }else {
            Integer id= Integer.parseInt(request.getParameter("id"));
            Integer result=auditoriumService.deleteAuditoriumById(id);
            if (result==-1){
                request.setAttribute("failMsg","你所需要删除的放映厅不存在！");
                request.getRequestDispatcher("/admin/auditorium_list?cinemaId="+request.getParameter("cinemaId")).forward(request,response);
            } else if (result>0) {
                request.setAttribute("msg","删除成功！");
                request.getRequestDispatcher("/admin/auditorium_list?cinemaId="+request.getParameter("cinemaId")).forward(request,response);
            }else {
                request.setAttribute("failMsg","删除失败！");
                request.getRequestDispatcher("/admin/auditorium_list?cinemaId="+request.getParameter("cinemaId")).forward(request,response);
            }
        }
    }
}
